import java.util.Scanner;

public class 递归实现排列型枚举 {
    private static int state[];
    private static boolean use[];
    private static int n;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        state = new int[n + 1];
        use = new boolean[n + 1];
        dfs(1);
    }

    private static void dfs(int u) {
        if (u > n) {
            //输出每个数
            for (int i = 1; i <= n; i++) {
                System.out.print(state[i] + " ");
            }
            System.out.println();
            return;
        }
        //遍历每一个数
        for (int i = 1; i <= n; i++) {
            if (!use[i]) {
                state[u] = i;
                use[i] = true;
                System.out.println("到达第"+u+"位"+",选择的数字为"+i);
                dfs(u + 1);
                use[i] = false;
            }
        }
    }

}
